#!/bin/bash
cp -r machineSetting.txt machineSetting_cc.txt
sed -i "s/\(\\\)\|\(\/\)\|\(\?\)\|\(\&\)\)/\\\\\\\\\1/g" machineSetting_cc.txt

echo "加载配置文件"

source ./machineSetting_cc.txt
while read line
do
  echo "  $line"
done < machineSetting.txt

rm -rf conf
mkdir conf
cp -r ./properties ./conf/
cp -r ./portainer ./conf/
cp -r ./sql ./conf/

echo "修改应用配置"
echo "  主节点名字修改"
sed -i "s/{master}/$master/g" `grep {master} -rl ./conf`

echo "  数据库链接修改"
sed -i "s/{dburl}/$dburl/g" `grep {dburl} -rl ./conf`

echo "  单点认证修改修改"
sed -i "s/{casUrl}/$casUrl/g" `grep {casUrl} -rl ./conf`
sed -i "s/{casEnable}/$casEnable/g" `grep {casEnable} -rl ./conf`

echo "  润乾报表地址修改"
sed -i "s/{reportUrl}/$reportUrl/g" `grep {reportUrl} -rl ./conf`

if grep hrm -q ../conf/properties/ly-gateway-server-svc-dev.yml; then 
  echo '检测到网关配置文件需要修改综合人事平台的服务名'
  cp -f ../conf/properties/ly-gateway-server-svc-dev.yml ../conf/properties/ly-gateway-server-svc-dev.yml.hrbak
  echo '  网关配置文件备份 到 ly-gateway-server-svc-dev.yml.hrbak'
  sed -i "s/ly-hrm-base-svc/ly-hr-base-svc/g" ../conf/properties/ly-gateway-server-svc-dev.yml
  sed -i "s/ly-hrm-teacherInfo-svc/ly-hr-teacher-info-svc/g" ../conf/properties/ly-gateway-server-svc-dev.yml
  sed -i "s/ly-hrm-organization-svc/ly-hr-organization-svc/g" ../conf/properties/ly-gateway-server-svc-dev.yml
  sed -i "s/ly-hrm-gatherInfo-svc/ly-hr-gather-info-svc/g" ../conf/properties/ly-gateway-server-svc-dev.yml
  sed -i "s/ly-hrm-business-svc/ly-hr-business-svc/g" ../conf/properties/ly-gateway-server-svc-dev.yml
  sed -i "s/ly-hrm-recruitment-svc/ly-hr-recruitment-svc/g" ../conf/properties/ly-gateway-server-svc-dev.yml
  echo '  网关配置文件修改完成'
else
  echo '网关配置文件不需要修改'
fi

echo "复制人事服务的properties文件到 /opt/docker-conf/conf/properties/"

cp -f ./conf/properties/* ../conf/properties/

echo "配置脚本执行成功！"

rm -f machineSetting_cc.txt
